package cn.zcj.studytest.controller;

import cn.zcj.studytest.ThrowData.Result;
import cn.zcj.studytest.domain.Lottery;
import cn.zcj.studytest.dto.LotteryDTO;
import cn.zcj.studytest.service.LotteryService;
import cn.zcj.studytest.vo.CommentVO;
import cn.zcj.studytest.vo.LotteryVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/lottery")
@Slf4j
public class LotteryController {
    @Resource
    private LotteryService lotteryService;

    Result<List<LotteryVO>> result = new Result<>();
    
    @PostMapping("/getAllName")
    public Result queryLottery(){

        try {
            return lotteryService.getLotteryName();
        }catch (Exception e){
            result.setMsg("获取失败");
            result.setSuccess(false);
            return result;
        }
    }

    /**
     * 抽奖接口
     * @param count 要抽取的中奖人数，可选参数，默认为1
     * @return 中奖人员列表
     */
    @PostMapping("/awardWinner/{count}")
    public Result awardWinner(@PathVariable Integer count){
        try {
            // 如果没有传入count参数，默认抽取1人
            if (count == null || count <= 0) {
                count = 1;
            }
            return lotteryService.awardWinner(count);
        }catch (Exception e){
            log.error("抽奖失败：", e);
            result.setMsg("抽奖失败：" + e.getMessage());
            result.setSuccess(false);
            return result;
        }
    }


}
